home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / libbonobo-2.0 / bonobo / bonobo-object.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-01-09  |  10.9 KB  |  252 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
  2. /**
  3.  * Bonobo Unknown interface base implementation
  4.  *
  5.  * Authors:
  6.  *   Miguel de Icaza (miguel@kernel.org)
  7.  *   Michael Meeks (michael@helixcode.com)
  8.  *
  9.  * Copyright 1999,2001 Ximian, Inc.
  10.  */
  11. #ifndef _BONOBO_OBJECT_H_
  12. #define _BONOBO_OBJECT_H_
  13.  
  14. #include <bonobo-activation/bonobo-activation.h>
  15.  
  16. #include <glib-object.h>
  17. #include <bonobo/Bonobo.h>
  18. #include <bonobo/bonobo-macros.h>
  19.  
  20. G_BEGIN_DECLS
  21.  
  22. #undef BONOBO_OBJECT_DEBUG
  23.  
  24. #define BONOBO_TYPE_OBJECT        (bonobo_object_get_type ())
  25. #define BONOBO_OBJECT_TYPE        BONOBO_TYPE_OBJECT /* deprecated, you should use BONOBO_TYPE_OBJECT */
  26. #define BONOBO_OBJECT(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), BONOBO_TYPE_OBJECT, BonoboObject))
  27. #define BONOBO_OBJECT_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), BONOBO_TYPE_OBJECT, BonoboObjectClass))
  28. #define BONOBO_IS_OBJECT(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), BONOBO_TYPE_OBJECT))
  29. #define BONOBO_IS_OBJECT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), BONOBO_TYPE_OBJECT))
  30. #define BONOBO_OBJECT_GET_CLASS(o)(G_TYPE_INSTANCE_GET_CLASS ((o), BONOBO_TYPE_OBJECT, BonoboObjectClass))
  31.  
  32. #define BONOBO_OBJREF(o)          (bonobo_object_corba_objref(BONOBO_OBJECT(o)))
  33.  
  34. typedef void  (*BonoboObjectPOAFn) (PortableServer_Servant servant,
  35.                     CORBA_Environment     *ev);
  36.  
  37. typedef struct _BonoboObjectPrivate BonoboObjectPrivate;
  38. typedef struct _BonoboObjectBag     BonoboObjectBag;
  39. typedef struct _BonoboObject        BonoboObject;
  40.  
  41. typedef struct {
  42.     GObject              base;             /* pointer + guint + pointer */
  43.     BonoboObjectPrivate *priv;             /* pointer */
  44.     guint                object_signature; /* guint   */
  45. } BonoboObjectHeader;
  46.  
  47. #define BONOBO_OBJECT_HEADER_SIZE (sizeof (BonoboObjectHeader))
  48. #define BONOBO_OBJECT_SIGNATURE   0xaef2
  49. #define BONOBO_SERVANT_SIGNATURE  0x2fae
  50.  
  51. struct _BonoboObject {
  52.     /* A GObject and its signature of type BonoboObjectHeader */
  53.     GObject              base;             /* pointer + guint + pointer */
  54.     BonoboObjectPrivate *priv;             /* pointer */
  55.     guint                object_signature; /* guint   */
  56.  
  57.     /* A Servant and its signature - same memory layout */
  58.     POA_Bonobo_Unknown   servant;          /* pointer + pointer */
  59.     guint                dummy;            /* guint   */
  60.     Bonobo_Unknown       corba_objref;     /* pointer */
  61.     guint                servant_signature;
  62. };
  63.  
  64. typedef struct {
  65.     GObjectClass parent_class;
  66.  
  67.     /* signals. */
  68.     void         (*destroy)          (BonoboObject *object);
  69.     void         (*system_exception) (BonoboObject *object,
  70.                       CORBA_Object  cobject,
  71.                       CORBA_Environment *ev);
  72.  
  73.     BonoboObjectPOAFn          poa_init_fn;
  74.     BonoboObjectPOAFn          poa_fini_fn;
  75.  
  76.     POA_Bonobo_Unknown__vepv       *vepv;
  77.  
  78.     /* The offset of this class' additional epv */
  79.     int                             epv_struct_offset;
  80.  
  81.     PortableServer_ServantBase__epv base_epv;
  82.     POA_Bonobo_Unknown__epv         epv;
  83.  
  84.     gpointer                        dummy[4];
  85. } BonoboObjectClass;
  86.  
  87. GType                    bonobo_object_get_type               (void) G_GNUC_CONST;
  88. void                     bonobo_object_add_interface          (BonoboObject           *object,
  89.                                    BonoboObject           *newobj);
  90. BonoboObject            *bonobo_object_query_local_interface  (BonoboObject           *object,
  91.                                    const char             *repo_id);
  92. Bonobo_Unknown           bonobo_object_query_remote           (Bonobo_Unknown          unknown,
  93.                                    const char             *repo_id,
  94.                                    CORBA_Environment      *opt_ev);
  95. Bonobo_Unknown           bonobo_object_query_interface        (BonoboObject           *object,
  96.                                    const char             *repo_id,
  97.                                    CORBA_Environment      *opt_ev);
  98. Bonobo_Unknown           bonobo_object_corba_objref           (BonoboObject           *object);
  99. void                     bonobo_object_set_poa                (BonoboObject           *object,
  100.                                    PortableServer_POA      poa);
  101.  
  102. /*
  103.  * Gnome Object Life Cycle
  104.  */
  105. Bonobo_Unknown           bonobo_object_dup_ref                (Bonobo_Unknown          object,
  106.                                    CORBA_Environment      *opt_ev);
  107. Bonobo_Unknown           bonobo_object_release_unref          (Bonobo_Unknown          object,
  108.                                    CORBA_Environment      *opt_ev);
  109. gpointer                 bonobo_object_ref                    (gpointer                obj);
  110. void                     bonobo_object_idle_unref             (gpointer                obj);
  111. gpointer                 bonobo_object_unref                  (gpointer                obj);
  112. void                     bonobo_object_set_immortal           (BonoboObject           *object,
  113.                                    gboolean                immortal);
  114. gpointer                 bonobo_object_trace_refs             (gpointer                obj,
  115.                                    const char             *fn,
  116.                                    int                     line,
  117.                                    gboolean                ref);
  118.  
  119. #ifdef BONOBO_OBJECT_DEBUG
  120. #    define           bonobo_object_ref(o)   bonobo_object_trace_refs ((o),G_GNUC_PRETTY_FUNCTION,__LINE__,TRUE);
  121. #    define           bonobo_object_unref(o) bonobo_object_trace_refs ((o),G_GNUC_PRETTY_FUNCTION,__LINE__,FALSE);
  122. #endif    /* BONOBO_OBJECT_DEBUG */
  123. void                     bonobo_object_dump_interfaces        (BonoboObject *object);
  124.  
  125. /*
  126.  * Error checking
  127.  */
  128. void                     bonobo_object_check_env              (BonoboObject           *object,
  129.                                    CORBA_Object            corba_object,
  130.                                    CORBA_Environment      *ev);
  131.  
  132. #define BONOBO_OBJECT_CHECK(o,c,e)                \
  133.             G_STMT_START {                \
  134.             if ((e)->_major != CORBA_NO_EXCEPTION)    \
  135.                 bonobo_object_check_env(o,c,e);    \
  136.             } G_STMT_END
  137.  
  138. /*
  139.  * Others
  140.  */
  141.  
  142. gboolean  bonobo_unknown_ping           (Bonobo_Unknown     object,
  143.                      CORBA_Environment *opt_ev);
  144. void      bonobo_object_list_unref_all  (GList            **list);
  145. void      bonobo_object_slist_unref_all (GSList           **list);
  146.  
  147. /*
  148.  * A weak-ref cache scheme
  149.  */
  150.  
  151. #define BONOBO_COPY_FUNC(fn) ((BonoboCopyFunc)(fn))
  152.  
  153. typedef gpointer (*BonoboCopyFunc) (gconstpointer key);
  154.  
  155. BonoboObjectBag *bonobo_object_bag_new      (GHashFunc       hash_func,
  156.                          GEqualFunc      key_equal_func,
  157.                          BonoboCopyFunc  key_copy_func,
  158.                          GDestroyNotify  key_destroy_func);
  159. BonoboObject    *bonobo_object_bag_get_ref  (BonoboObjectBag *bag,
  160.                          gconstpointer    key);
  161. gboolean         bonobo_object_bag_add_ref  (BonoboObjectBag *bag,
  162.                          gconstpointer    key,
  163.                          BonoboObject    *object);
  164. void             bonobo_object_bag_remove   (BonoboObjectBag *bag,
  165.                          gconstpointer    key);
  166. void             bonobo_object_bag_destroy  (BonoboObjectBag *bag);
  167. GPtrArray       *bonobo_object_bag_list_ref (BonoboObjectBag *bag);
  168.  
  169.  
  170. /* Detects the pointer type and returns the object reference - magic. */
  171. BonoboObject *bonobo_object (gpointer p);
  172. /* The same thing but faster - has a double evaluate */
  173. #define       bonobo_object_fast(o) \
  174.     ((((BonoboObjectHeader *)(o))->object_signature == BONOBO_OBJECT_SIGNATURE) ? \
  175.      (BonoboObject *)(o) : (BonoboObject *)(((guchar *) (o)) - BONOBO_OBJECT_HEADER_SIZE))
  176.  
  177. /* Compat */
  178. #define       bonobo_object_from_servant(s) ((BonoboObject *)(((guchar *) (s)) - BONOBO_OBJECT_HEADER_SIZE))
  179. #define       bonobo_object_get_servant(o)  ((PortableServer_Servant)((guchar *)(o) + BONOBO_OBJECT_HEADER_SIZE))
  180.  
  181.  
  182. PortableServer_POA bonobo_object_get_poa (BonoboObject *object);
  183.  
  184. /* Use G_STRUCT_OFFSET to calc. epv_struct_offset */
  185. GType          bonobo_type_unique (GType             parent_type,
  186.                    BonoboObjectPOAFn init_fn,
  187.                    BonoboObjectPOAFn fini_fn,
  188.                    int               epv_struct_offset,
  189.                    const GTypeInfo  *info,
  190.                    const gchar      *type_name);
  191.  
  192. gboolean       bonobo_type_setup  (GType             type,
  193.                    BonoboObjectPOAFn init_fn,
  194.                    BonoboObjectPOAFn fini_fn,
  195.                    int               epv_struct_offset);
  196.  
  197. #define BONOBO_TYPE_FUNC_FULL(class_name, corba_name, parent, prefix)         \
  198. GType                                                                         \
  199. prefix##_get_type (void)                                                      \
  200. {                                                                             \
  201.     GType ptype;                                                          \
  202.     static GType type = 0;                                                \
  203.                                                                               \
  204.     if (type == 0) {                                                      \
  205.         static GTypeInfo info = {                                     \
  206.             sizeof (class_name##Class),                           \
  207.             (GBaseInitFunc) NULL,                                 \
  208.             (GBaseFinalizeFunc) NULL,                             \
  209.             (GClassInitFunc) prefix##_class_init,                 \
  210.             NULL, NULL,                                           \
  211.             sizeof (class_name),                                  \
  212.             0,                                                    \
  213.             (GInstanceInitFunc) prefix##_init                     \
  214.         };                                                            \
  215.         ptype = (parent);                                             \
  216.         type = bonobo_type_unique (ptype,                             \
  217.             POA_##corba_name##__init, POA_##corba_name##__fini,   \
  218.             G_STRUCT_OFFSET (class_name##Class, epv),             \
  219.             &info, #class_name);                                  \
  220.     }                                                                     \
  221.     return type;                                                          \
  222. }
  223.  
  224. #define BONOBO_TYPE_FUNC(class_name, parent, prefix)                        \
  225. GType                                                                         \
  226. prefix##_get_type (void)                                                      \
  227. {                                                                             \
  228.     GType ptype;                                                          \
  229.     static GType type = 0;                                                \
  230.                                                                               \
  231.     if (type == 0) {                                                      \
  232.         static GTypeInfo info = {                                     \
  233.             sizeof (class_name##Class),                           \
  234.             (GBaseInitFunc) NULL,                                 \
  235.             (GBaseFinalizeFunc) NULL,                             \
  236.             (GClassInitFunc) prefix##_class_init,                 \
  237.             NULL, NULL,                                           \
  238.             sizeof (class_name),                                  \
  239.             0,                                                    \
  240.             (GInstanceInitFunc) prefix##_init                     \
  241.         };                                                            \
  242.         ptype = (parent);                                             \
  243.         type = bonobo_type_unique (ptype, NULL, NULL, 0,              \
  244.                            &info, #class_name);               \
  245.     }                                                                     \
  246.     return type;                                                          \
  247. }
  248.  
  249. G_END_DECLS
  250.  
  251. #endif
  252.